/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import constants.*;
/**
 *
 * @author Đức Trung
 */
public class RoomModel extends AbstractTableModel {

       
    ArrayList<entity.Room> list ;
    public RoomModel(ArrayList<entity.Room> list ){
        this.list = list;
    }
    public final static String[] columnNames = {
       "STT","Mã phòng","Tên phòng","Loại phòng","Giá","Tình trạng"
    };
    public int getRowCount() {
       return list.size();
    }

    public int getColumnCount() {
        return columnNames.length;
    }

    public Object getValueAt(int row, int col) {
          switch(col){
              case 0: return row+1;
              case 1:return list.get(row).getId()   ;         
              case 2:return list.get(row).getName() ;
              case 3:return list.get(row).getRoomtype().getName();
              case 4: return list.get(row).getRoomtype().getCost()+"$";    
              case 5: return Constants.STATUS_NAME[list.get(row).getStatus()];                 
              default: return null;  
            }
    }
    public String getColumnName(int columnIndex) {
        return columnNames[columnIndex];
    }
      public void refesh(){
        fireTableDataChanged();
    }
    public void removeRow(int row) {
        list.remove(row);
        fireTableDataChanged();
    }
    public void insertList(entity.Room e){
        list.add(e);
        fireTableDataChanged();       
    }
    public void editList(int index,entity.Room e){
        list.remove(index);
        list.add(index, e);
        fireTableDataChanged();    
    }
}
